package com.tuling.learnjuc.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author: Fox
 * @Desc: TODO 结果的转换
 **/
public class CFDemo3 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // TODO 试着把这段注释掉观察线程池
        CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "执行有返回值的异步任务");
            return "Hello World";
        });

        // TODO 观察体现结果
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            int result = 100;
            System.out.println(Thread.currentThread().getName() + "一阶段：" + result);
            return result;
        }).thenApplyAsync(number -> {// TODO Async意味着可能会新开线程
            int result = number * 3;
            System.out.println(Thread.currentThread().getName() + "二阶段：" + result);
            return result;
        });

        System.out.println(Thread.currentThread().getName() + "最终结果：" + future.get());


    }
}
